home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /* PROJEKT PR4WIN Service DLL */
- /* */
- /* This is a sample for a Pr4Win Service implemented as a DLL */
- /* */
- /* */
- /* */
- /* */
- /* */
- /* BY: */
- /* ---------- */
- /* OE8DJK Bernd M. Stroj 18.01.1996 */
- /* */
- /*****************************************************************************/
-
- #include "windows.h"
- #include "stdlib.h"
- #include "string.h"
- #include "srvdll.h"
-
-
-
- #define VERSION 102 // becones 1.02 in remote conmmand //SERV
-
- #define CR 13
- #define LF 10
-
-
- typedef struct
- {
- long hCon; // Handle to Connection
- char szCallSign[10]; // E.G."OE8DJK-15"
- char szInpBuffer[128]; // contains complete inputline
- short sCount; // Characters in szInpBuffer
- void *ptPrivat; // pointer to private data
- void *ptNextCon; // Daisy chain
- } CON_DATA;
-
- static CON_DATA *ptFirstCon = NULL;
-
-
- static FARPROC lpfnSnd2Con; // Service -> Connect
- static FARPROC lpfnControl; // Service connection
-
-
- static void vAddCon ( CON_DATA *ptCon );
- static void vDelCon ( long hCon );
- static CON_DATA *ptGetCon ( long hCon );
- static void vService ( long hCon, CON_DATA *ptCon );
- static void vExitService ( long hCon, CON_DATA *ptCon );
-
-
-
-
- /*----------------------------------------------------------------------------*/
- /* Procedure: LibMain */
- /* Called by LibEntry, when DLLis loaded */
- /* */
- /* Parameters: hModule Module Handle */
- /* wDataSeg Data Segment */
- /* cbHeapSize Heap Size */
- /* lpszCmdLine Command Line */
- /* */
- /* Returns: 1 wenn OK */
- /* */
- /*----------------------------------------------------------------------------*/
-
- int FAR PASCAL LibMain (HANDLE hModule, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine)
- {
- return (1);
- }
-
- /*----------------------------------------------------------------------------*/
- /* */
- /* FUNCTION: DllMain(HANDLE, DWORD, LPVOID) */
- /* */
- /* PURPOSE: DllMain is called by Windows when */
- /* the DLL is initialized, Thread Attached, and other times. */
- /* Refer to SDK documentation, as to the different ways this */
- /* may be called. */
- /* */
- /* The DllMain function should perform additional initialization */
- /* tasks required by the DLL. In this example, no initialization */
- /* tasks are required. DllMain should return a value of 1 if */
- /* the initialization is successful. */
- /* */
- /* */
- /*----------------------------------------------------------------------------*/
-
- BOOL APIENTRY DllMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved)
- {
- return 1;
- UNREFERENCED_PARAMETER(hInst);
- UNREFERENCED_PARAMETER(ul_reason_being_called);
- UNREFERENCED_PARAMETER(lpReserved);
- }
-
-
-
-
-
- /*----------------------------------------------------------------------------*/
- /* Procedure: iInitDll */
- /* Initialisiert den Service, meldet Callback Fkt an. */
- /* */
- /* Parameters: ptInitServer */
- /* */
- /* Returns: 1 if OK */
- /* */
- /*----------------------------------------------------------------------------*/
-
-
- int APIENTRY iInitDll ( INIT_SERVICE *ptInitSrv )
- {
- lpfnSnd2Con = ptInitSrv->lpfnAns;
- lpfnControl = ptInitSrv->lpfnCtl;
- return (1);
- }
-
-
- /*----------------------------------------------------------------------------*/
- /* Procedure: iExitDll */
- /* */
- /* Parameters: ptInitServer */
- /* */
- /* Returns: 1 if OK */
- /* */
- /*----------------------------------------------------------------------------*/
-
-
- int APIENTRY iExitDll ( void )
- {
- return (1);
- }
-
-
- /*----------------------------------------------------------------------------*/
- /* Procedure: iOpenSrv */
- /* A Station requiers a connect to a service */
- /* */
- /* Parameters: ptOpenSrv */
- /* */
- /* Returns: 1 if OK */
- /* 0 if conenction is refused, apply a text in ptOpenSrv->stError */
- /* to explain the reason for refuse ! */
- /* */
- /*----------------------------------------------------------------------------*/
-
-
- int APIENTRY iOpenSrv ( OPEN_SERVICE *ptOpenSrv )
- {
- CON_DATA *ptCon;
-
- ptCon = malloc(sizeof(CON_DATA));
- memset ( ptCon, 0x00, sizeof(CON_DATA));
-
- ptCon->hCon=ptOpenSrv->hCon;
- strcpy(ptCon->szCallSign,ptOpenSrv->szCallSign);
- vAddCon(ptCon);
-
- // A maximum of 127 characters is permited in welcome text !
-
- strcpy(ptOpenSrv->szError,"Welcome to the demo service, ");
- strcat(ptOpenSrv->szError,ptOpenSrv->szCallSign);
- strcat(ptOpenSrv->szError," !\n\r");
- strcat(ptOpenSrv->szError,"Enter //EXIT to exit service !");
-
- return (1);
- }
-
-
- /*----------------------------------------------------------------------------*/
- /* Procedure: iCloseSrv */
- /* A Connect is closed without colosing the Service before. */
- /* */
- /* Parameters: hCon Connection Handle = Connect Window */
- /* */
- /* Returns: 1 if OK */
- /* */
- /*----------------------------------------------------------------------------*/
-
-
- int APIENTRY iCloseSrv( long hCon )
- {
- vDelCon ( hCon );
- return (1);
- }
-
-
- /*----------------------------------------------------------------------------*/
- /* Procedure: iSnd2Srv */
- /* The connected station sends a data package to ther service. */
- /* */
- /* Parameters: ptSrv contains connection handle und Daten package. */
- /* */
- /* Returns: 1 wenn OK */
- /* */
- /*----------------------------------------------------------------------------*/
-
-
- int APIENTRY iSnd2Srv( RXTX_SERVICE *ptSrv )
- {
- CON_DATA *ptCon;
- short i;
-
- ptCon=ptGetCon(ptSrv->hCon);
-
- for ( i=0; i < ptSrv->sPacLen; i++)
- {
- if (ptSrv->sPacket[i] == CR || ptSrv->sPacLen >= 127 )
- {
- ptCon->szInpBuffer[ptCon->sCount]='\0';
- vService ( ptSrv->hCon, ptCon ); // proccess a mplete Line
- ptCon->sCount=0;
-
- }
- else
- if (ptSrv->sPacket[i] != LF)
- ptCon->szInpBuffer[ptCon->sCount++]=ptSrv->sPacket[i];
- }
- return (1);
- }
-
-
- /*----------------------------------------------------------------------------*/
- /* Procedure: iVersion */
- /* Get the version ot the DLL. */
- /* */
- /* Parameters: void */
- /* */
- /* Returns: Version */
- /* */
- /*----------------------------------------------------------------------------*/
-
-
- int APIENTRY iVersion ( void )
- {
- return (VERSION);
- }
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- /* */
- /* vAddCon */
- /* */
- /* Appends a CON record to the linked structure. */
- /* */
- /* */
- /* */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- static void vAddCon ( CON_DATA *ptCon )
- {
- CON_DATA *ptHlp;
-
- if ( ptFirstCon == NULL )
- ptFirstCon=ptCon;
- else
- {
- for ( ptHlp=ptFirstCon;
- ptHlp->ptNextCon != NULL;
- ptHlp = (CON_DATA *) ptHlp->ptNextCon
- );
-
- ptHlp->ptNextCon = (void *) ptCon;
- }
- }
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- /* */
- /* vDelCon */
- /* */
- /* Delets a CON record from the linked structure. */
- /* */
- /* */
- /* */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- static void vDelCon ( long hCon )
- {
- CON_DATA *ptHlp=NULL;
- CON_DATA *ptPrev=NULL;
-
- for ( ptHlp=ptFirstCon;
- ptHlp!=NULL;
- ptPrev=ptHlp, ptHlp=(CON_DATA *)ptHlp->ptNextCon )
- {
- if (ptHlp->hCon == hCon)
- {
- if (ptPrev)
- ptPrev->ptNextCon=(void *)ptHlp->ptNextCon;
- else
- ptFirstCon=(void *)ptHlp->ptNextCon;
-
- free( (char *)ptHlp);
- break;
- }
- }
- }
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- /* */
- /* vGetCon */
- /* */
- /* Gets the connection structure from a connection handle. */
- /* */
- /* */
- /* */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- static CON_DATA *ptGetCon ( long hCon )
- {
- CON_DATA *ptHlp=NULL;
-
- for ( ptHlp=ptFirstCon;
- ptHlp!=NULL && ptHlp->hCon != hCon;
- ptHlp=(CON_DATA *)ptHlp->ptNextCon );
-
- return ( ptHlp );
- }
-
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- /* */
- /* vExitService */
- /* */
- /* Ein Service wird con einem Connect beendet. . */
- /* */
- /* */
- /* */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- static void vExitService ( long hCon, CON_DATA *ptCon )
- {
- RXTX_SERVICE *ptData;
-
- ptData = malloc(sizeof(RXTX_SERVICE));
- memset ( ptData, 0x00, sizeof(RXTX_SERVICE));
-
- ptData->hCon = hCon;
- strcpy(ptData->sPacket,"Goodby from ECHO Service, ");
- strcat(ptData->sPacket,ptCon->szCallSign);
- strcat(ptData->sPacket," \n\r");
- ptData->sPacLen=strlen(ptData->sPacket);
- (*lpfnSnd2Con) (ptData);
- (*lpfnControl) (ptCon->hCon, SRV_EXIT, NULL );
- free ( (char *)ptData);
- }
-
-
-
- static void vService ( long hCon, CON_DATA *ptCon )
- {
- RXTX_SERVICE *ptData;
-
-
- if ( strstr(ptCon->szInpBuffer,"//EXIT") )
- {
- vExitService ( hCon, ptCon );
- return;
- }
-
- ptData = malloc(sizeof(RXTX_SERVICE));
- memset ( ptData, 0x00, sizeof(RXTX_SERVICE));
-
- ptData->hCon = hCon;
- strcpy(ptData->sPacket,"<");
- strcat(ptData->sPacket,ptCon->szCallSign);
- strcat(ptData->sPacket,">");
- strcat(ptData->sPacket,ptCon->szInpBuffer);
- strcat(ptData->sPacket,"\n\r");
-
- ptData->sPacLen=strlen(ptData->sPacket);
- (*lpfnSnd2Con) (ptData);
- free ( (char *)ptData);
- }
-